package com.example.waterorder.controller;

import com.example.waterorder.entity.constant.WaterMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mq")
public class RabbitMQController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    private String exchangeName = "order.exchange";

    @PostMapping("")
    public void sendOrderMessage(@RequestParam("key") String key){
        rabbitTemplate.convertAndSend(exchangeName,key, WaterMessage.ORDER_NEW);
    }

    @GetMapping("/front")
    public void sendFrontMessage(){
        System.out.println("发送消息");
        // 队列名称
        String queueName = "simple.queue";
        // 消息
        String message = "hello, spring amqp!";
        // 发送消息
        rabbitTemplate.convertAndSend(queueName, message);
    }

    @GetMapping("/hello")
    public String test(){
        return "hello";
    }
}
